﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using MySql.Data.MySqlClient;


public class SegmentDetail
{
#region members
    private int m_month = 0;
    private int m_score = 0;

#endregion

    public int Month
    {
        get { return m_month; }
        set { m_month = value;}
    }

    public int Score
    {
        get { return m_score; }
        set { m_score = value; }
    }

};

/// <summary>
/// SegmentDb 的摘要说明
/// </summary>
public class SegmentDb: CommonDb
{
	public SegmentDb()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public SegmentDetail GetSegmentScore()
    {
        MySqlCommand cmd = new MySqlCommand("select Score from segment where Id = 1", m_conn);
        try
        {
            m_conn.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            SegmentDetail segInfo = new SegmentDetail();
            segInfo.Month = DateTime.Today.Month;
            if(reader.Read())
            {
                segInfo.Score = (int)reader["Score"];
            }
            return segInfo;

        }
        catch(MySqlException err)
        {
            throw new ApplicationException(err.ToString());
        }
        finally
        {
            m_conn.Close();
        }
    }

    public void UpdateSegmentScore(SegmentDetail segInfo)
    {
        MySqlCommand cmd = DataComponent.CreateMySqlProcCmd("UpdateSegmentScore", m_conn);
        DataComponent.AddCmdParameters(cmd, "?segScore", MySqlDbType.Int32, 10, segInfo.Score);
        DataComponent.ExecNonQueryCmd(cmd, m_conn);

    }

    
}
